﻿using System;
using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_136 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 50000000;
            //const int max = 100;

            long res = 0;

            for (long n = 1; n <= max; n++)
            {
                long cnt = 0;
                long mx = (long)Math.Sqrt(n);
                for (long y = 1; y <= mx; y++)
                {
                    if (n%y != 0)
                        continue;
                    var q = n/y;
                    if ((q+y)%4 ==0)
                    {
                        cnt++;
                        if (y < mx && (q<3*y))
                            cnt++;
                    }
                    if (cnt >= 2) break;
                }
                if (cnt == 1)
                    res++;
            }

            return res;
        }

        public override string Problem
        {
            get
            {
                return @"The positive integers, x, y, and z, are consecutive terms of an arithmetic progression. Given that n is a positive integer, the equation, x2  y2  z2 = n, has exactly one solution when n = 20:

132  102  72 = 20

In fact there are twenty-five values of n below one hundred for which the equation has a unique solution.

How many values of n less than fifty million have exactly one solution?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 2544559;
            }
        }
    }
}
